package com.fwj.common.service;

import com.fwj.common.api.MailService;
import com.fwj.core.common.common.CommonUtils;
import com.fwj.core.common.common.MailUtil;
import com.fwj.core.common.common.PropertiesFileUtil;
import com.fwj.core.common.constant.CoreConstant;
import com.fwj.core.common.execption.CommonException;
import com.fwj.core.common.model.Mail;
import com.fwj.core.common.model.ResponseDTO;
import com.fwj.core.common.model.ResponseEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * @Author: fwj
 * @Data: 2022/5/3 4:09
 * @Version 1.0
 * @Description:
 */

@Service
public class MailServiceImpl implements MailService {

    //添加日志工厂
    private static final Logger LOGGER = LoggerFactory.getLogger(MailServiceImpl.class);

//    @Autowired
//    private MailMapper mailMapper;
    /**
     * @Description: TODO 发送邮件
     * @param mail 发送邮件实体,需要自构建
     * @return
     */
    @Override
    public ResponseDTO sendMail(Mail mail) {
        try {
            //发送邮件
            MailUtil.sendMail(mail);
            //记录邮件发送记录
            return new ResponseDTO<>().success();
        } catch (Exception e) {
            LOGGER.error(e.toString());
            return new ResponseDTO<>().fail();
        }
    }

}
